package com.bilgeadam.hibernate.program;

import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

/**
 * 
 * @author Bora SAYINER
 * @since Nov 15, 2014 3:57:55 PM
 * @version 1.0.0
 */
public class Driver {

	public static void main(String[] args) {
		SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
		Session session = sessionFactory.openSession();
		Transaction transaction = session.beginTransaction();
		{
			Project projects = (Project) session.get(Project.class, 1L);
			Set<Employee> employees = projects.getEmployees();
			for (Employee employee : employees) {
				System.out.println(employee);
			}
			
//			Project javaWebProjesi = new Project();
//			javaWebProjesi.setName("Java Web Projesi");
//			session.save(javaWebProjesi);
//			
//			Project androidProjesi = new Project();
//			androidProjesi.setName("Android Projesi");
//			session.save(androidProjesi);
//			{
//				Employee nigar = new Employee();
//				nigar.setFirstName("Nigar");
//				nigar.setLastName("DURMUŞ");
//				nigar.getProjects().add(javaWebProjesi);
//				nigar.getProjects().add(androidProjesi);
//				session.save(nigar);
//			}
//			{
//				Employee haluk = new Employee();
//				haluk.setFirstName("Haluk");
//				haluk.setLastName("GWT");
//				haluk.getProjects().add(androidProjesi);
//				session.save(haluk);
//			}		
			
		}
		transaction.commit();
		session.close();
		sessionFactory.close();
	}
}
